****TABLE 3****

cd "$main_dir/output/tables/main"

global basic 	sex marital religion edu ethnicity birth_state
global extra	employment_status occupation income urban
global time 	survey_year age generation
global polit    party partisan

//--------------------------------------------------------
//Generate relevant program
//--------------------------------------------------------

capture program drop standardize_depvar
program define standardize_depvar
	
	args depvar
	
	cap drop z*
	local varlist `depvar' wgrowth_rate_1 yob_ln_gdppc
	foreach var of local varlist {
		egen z`var' = std(`var') if e(sample)==1
}														

end

//--------------------------------------------------------
//Read in relevant datasets
//--------------------------------------------------------

clear
use "$data_dir/clean/anes_final.dta"

egen scode_survey_year = group(state_code survey_year)

//--------------------------------------------------------
//Create Table 3
//--------------------------------------------------------

//Column 1
qui reghdfe trust_fed_govt wgrowth_rate_1 yob_ln_gdppc, absorb(state_code $time $basic $extra $polit) cluster(yob)
standardize_depvar trust_fed_govt												
reghdfe ztrust_fed_govt zwgrowth_rate_1 zyob_ln_gdppc, absorb(state_code $time $basic $extra $polit) cluster(yob)
outreg2 using table_3.doc, replace dec(3) nocons addtext(State FE, Yes, ///
													     Survey Year FE, Yes, ///
													     Generation FE, Yes, ///
													     State FE x Survey Year FE, No) keep(zwgrowth_rate_1)
														 
//results interpretation
qui summ trust_fed_govt if e(sample)==1
qui scalar beta_usa = _b[zwgrowth_rate_1]*r(sd)
qui summ trust_fed_govt if e(sample)==1 & generation=="millenial"
qui scalar trust_millenials = r(mean)
qui summ trust_fed_govt if e(sample)==1 & generation=="baby_boomer"
qui scalar trust_boomers = r(mean)
di abs(beta_usa)/(abs(trust_millenials-trust_boomers))
summ wgrowth_rate_1 if e(sample)==1														 

//Column 2										   
qui reghdfe trust_fed_govt wgrowth_rate_1 yob_ln_gdppc, absorb(scode_survey_year $time $basic $extra $polit) cluster(yob)
standardize_depvar trust_fed_govt
reghdfe ztrust_fed_govt zwgrowth_rate_1 zyob_ln_gdppc, absorb(scode_survey_year $time $basic $extra $polit) cluster(yob)
outreg2 using table_3.doc, append dec(3) nocons addtext(State FE, No, ///
													    Survey Year FE, No, ///
													    Generation FE, Yes, ///
													    State FE x Survey Year FE, Yes) keep(zwgrowth_rate_1) 																												   
													   
//Column 3										   
qui reghdfe trust_govt_index wgrowth_rate_1 yob_ln_gdppc, absorb(state_code $time $basic $extra $polit) cluster(yob)
standardize_depvar trust_govt_index	
reghdfe ztrust_govt_index zwgrowth_rate_1 zyob_ln_gdppc, absorb(state_code $time $basic $extra $polit) cluster(yob)
outreg2 using table_3.doc, append dec(3) nocons addtext(State FE, Yes, ///
													    Survey Year FE, Yes, ///
													    Generation FE, Yes, ///
													    State FE x Survey Year FE, No) keep(zwgrowth_rate_1) 																	

//Column 4											   
qui reghdfe trust_govt_index wgrowth_rate_1 yob_ln_gdppc, absorb(scode_survey_year $time $basic $extra $polit) cluster(yob)
standardize_depvar trust_govt_index
reghdfe ztrust_govt_index zwgrowth_rate_1 zyob_ln_gdppc, absorb(scode_survey_year $time $basic $extra $polit) cluster(yob)
outreg2 using table_3.doc, append dec(3) nocons addtext(State FE, No, ///
													    Survey Year FE, No, ///
													    Generation FE, Yes, ///
													    State FE x Survey Year FE, Yes) keep(zwgrowth_rate_1) 	

//Column 5													   
qui reghdfe trust_others wgrowth_rate_1 yob_ln_gdppc, absorb(state_code $time $basic $extra $polit) cluster(yob)
standardize_depvar trust_others
reghdfe ztrust_others zwgrowth_rate_1 zyob_ln_gdppc, absorb(state_code $time $basic $extra $polit) cluster(yob)
outreg2 using table_3.doc, append dec(3) nocons addtext(State FE, Yes, ///
													    Survey Year FE, Yes, ///
													    Generation FE, Yes, ///
													    State FE x Survey Year FE, No) keep(zwgrowth_rate_1) 		

//Column 6													   
qui reghdfe trust_others wgrowth_rate_1 yob_ln_gdppc, absorb(scode_survey_year $time $basic $extra $polit) cluster(yob)
standardize_depvar trust_others
reghdfe ztrust_others zwgrowth_rate_1 zyob_ln_gdppc, absorb(scode_survey_year $time $basic $extra $polit) cluster(yob)
outreg2 using table_3.doc, append dec(3) nocons addtext(State FE, No, ///
													    Survey Year FE, No, ///
													    Generation FE, Yes, ///
													    State FE x Survey Year FE, Yes) keep(zwgrowth_rate_1) 
